<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="d1">{{ab}}</div>
  </body>
  <script>
    // function fn() {
    //   console.log(123);
    // }
    // console.log(fn());
    var div = document.querySelector("#d1");
    var regex = /{{.*}}/; //匹配的字符串是：{{    +  除了转义字符外的任意字符0次或无穷次  +   }}
    var searches = regex.exec(div.innerText)[0]; //exec()函数返回值为数组类型,searches=["{{ab}}"]
    var cb = /[({{)(}})]/g; //全局匹配两组字符  {{ + }}
    var s = searches.match(cb); //s = ["{{","}}"]
    for (let i = 0; i < s.length; i++) {
      searches = searches.replace(s[i], "");
    } //searches = ["ab"]
    var prototype = {
      ab: 11111,
    };
    if (prototype[searches]) {
      div.innerText = prototype[searches]; //11111
    } else {
      console.log("not found");
    }
  </script>
</html>
